package com.xkstream.client.presenter;

import com.xkstream.client.api.LiveApi;
import com.xkstream.client.api.LiveService;
import com.xkstream.client.base.BaseData;
import com.xkstream.client.base.BasePresenterImpl;
import com.xkstream.client.entity.kt.GiftRankingData;
import com.xkstream.client.rx.RxHelper;
import com.xkstream.client.rx.RxObserver;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by xiaoyi on 2017-8-28.
 */

public class GiftContributionPresenter extends BasePresenterImpl implements GiftContributionContract.Presenter {
    private GiftContributionContract.View view;
    private LiveService liveService;

    public GiftContributionPresenter(GiftContributionContract.View view) {
        this.view = view;
        this.liveService = LiveApi.getInstance().service;
    }

    @Override
    public void getGiftRankingData(String userCode) {
        Map<String, Object> params = new HashMap<>();
        params.put("anchor_user_code", userCode);
        view.showLoading();
        liveService.getGiftRanking(params)
                .compose(RxHelper.toUI())
                .subscribe(new RxObserver<BaseData<GiftRankingData>>(this) {
                    @Override
                    protected void onSuccess(BaseData<GiftRankingData> data) {
                        view.hideLoading();
                        view.showGiftRankingData(data);
                    }

                    @Override
                    protected void onFail(String message) {
                        view.hideLoading();
                    }
                });
    }
}
